import 'package:bruno/bruno.dart';
import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:get/get.dart';
import 'package:yt_devops/components/app_bar/app_bar_widget.dart';
import 'package:yt_devops/components/brn/brn_input_text.dart';
import 'package:yt_devops/components/select_phone_widget.dart';
import 'package:yt_devops/components/yt_button.dart';
import 'package:yt_devops/resources/str_res_keys.dart';
import 'package:yt_devops/styles/styles.dart';
import 'suggestion_controller.dart';

class SuggestionPage extends GetView<SuggestionController> {
  const SuggestionPage({Key? key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return GestureDetector(
      onTap: () {
        if (FocusScope.of(context).hasFocus) {
          FocusScope.of(context).unfocus();
        }
      },
      child: GetBuilder<SuggestionController>(
        builder: (controller) => Scaffold(
          // backgroundColor: Colors.white,
          appBar: AppBarWidget.defaultAppBar(ResKey.feedback.tr),
          body: Column(
            mainAxisAlignment: MainAxisAlignment.start,
            crossAxisAlignment: CrossAxisAlignment.start,
            children: [
              Container(
                clipBehavior: Clip.hardEdge,
                  margin: const EdgeInsets.only(left: 16,right: 16,top: 10),
                  decoration: BoxDecoration(
                    borderRadius: BorderRadius.circular(8),
                    color: Colors.white,
                  ),
                  child: Column(
                    // shrinkWrap: false,
                    children: [
                      Container(
                        color: Colour.white,
                        alignment: Alignment.centerLeft,
                        padding:
                            EdgeInsets.only(left: 6.w, bottom: 8.h, top: 14.h),
                        child: Text.rich(TextSpan(
                            text: '* ',
                            children: [
                              TextSpan(
                                  text: ResKey.problemStastic.tr,
                                  style: TextStyles.f16.boldStyle),
                            ],
                            style: TextStyles.f14.warningColorStyle)),
                      ),
                      wrap(
                        child: YBrnInputText(
                          minHeight: 120.h,
                          maxHeight: 120.h,
                          minLines: 5,
                          maxLength: 200,
                          autoFocus: false,
                          hint: ResKey.pleDetailedDesYourIssue.tr,
                          bgColor: Colour.backgroundColor,
                          padding: EdgeInsets.fromLTRB(16.w, 16.h, 12.w, 12.h),
                          textEditingController: controller.contentController,
                          onTextChange: (input) => controller.textChange(input),
                        ),
                      ),
                      SelectPhotoWidget(
                        controller.deviceImageList,
                        true,
                        3,
                        photoWidth: 84,
                        titleFontSize: 16,
                        titleString: ResKey.uploadPic.tr,
                        (List<String> list) {
                          controller.deviceImageList = list;
                          controller.update();
                        },
                      ),
                    ],
                  ),
                ),

            ],
          ),
          bottomNavigationBar: Container(
            color: Colour.white,
            padding: EdgeInsets.only(
                left: 16,
                right: 16,
                top: 16,
                bottom: 16 + ScreenUtil().bottomBarHeight),
            child: controller.buttonEnabled
                ? YtButton(
                    color: Colour.primaryColor,
                    text: ResKey.submit.tr,
                    onPress: () => controller.commit(),
                  )
                : YtButton(
                    color: Colour.diabledButtoBgColor,
                    text: ResKey.submit.tr,
                  ),
          ),
        ),
      ),
    );
  }

  Widget wrap({String? title, String? subTitle, required Widget child}) {
    return Container(
      padding: EdgeInsets.only(
        left: 16.w,
        bottom: 16.w,
        right: 16.w,
        top: 10.h,
      ),
      color: Colour.white,
      child: Column(crossAxisAlignment: CrossAxisAlignment.start, children: [
        if (title != null)
          Container(
            height: 48.h,
            alignment: Alignment.centerLeft,
            child: Text.rich(
              TextSpan(text: title, style: TextStyles.f16.boldStyle, children: [
                if (subTitle != null)
                  TextSpan(text: subTitle, style: TextStyles.lf12)
              ]),
            ),
          ),
        child
      ]),
    );
  }
}
